package com.dxl.dao.common.context;

import com.dxl.bean.session.Session;
import com.dxl.common.utils.Utils;
import com.dxl.entity.account.Account;

public class SessionContext {
	private static final ThreadLocal<Session> CTX = new ThreadLocal<Session>();
	
	public static Session getSession() {
		return CTX.get();
	}

	public static void setSession(Session session) {
		CTX.set(session);
	}
	
	public static String getSessionId() {
		Session session = getSession();
		return Utils.isNotNull(session) ? session.getId() : "";
	}
	
	public static String getAccountId() {
		Session session = getSession();
		if (Utils.isNull(session)) {
			return null;
		}
		Account account = session.getAccount();
		if (Utils.isNull(account)) {
			return null;
		}
		return account.getId();
	}
	
	public static String getAccountName() {
		Session session = getSession();
		return Utils.isNotNull(session) ? (Utils.isNotNull(session.getAccount()) ? session.getAccount().getName() : null) : "";
	}
	
	public static String getAccount() {
		Session session = getSession();
		return Utils.isNotNull(session) ? (Utils.isNotNull(session.getAccount()) ? session.getAccount().getAccount() : null) : "";
	}
}
